package com.shanks.framework.mq.data.mybatis.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shanks.framework.mq.data.mybatis.mapper.MessageConsumeExceptionRecordMapper;
import com.shanks.framework.mq.model.MessageConsumeExceptionRecordPO;
import com.shanks.framework.mq.repository.MessageConsumeExceptionRecordRepository;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MessageConsumeExceptionRecordRepositoryImpl implements MessageConsumeExceptionRecordRepository {
    @Resource
    private MessageConsumeExceptionRecordMapper messageConsumeExceptionRecordMapper;

    @Override
    public void insertExceptionRecord(MessageConsumeExceptionRecordPO messageConsumeExceptionRecordPO) {
        messageConsumeExceptionRecordMapper.insert(messageConsumeExceptionRecordPO);
    }

    @Override
    public void deleteExceptionRecordByMsgTopicTagKey(String topic, String tags, String key) {
        messageConsumeExceptionRecordMapper.update(Wrappers.lambdaUpdate(MessageConsumeExceptionRecordPO.class)
                .eq(MessageConsumeExceptionRecordPO::getMsgTopic, topic)
                .eq(MessageConsumeExceptionRecordPO::getMsgTag, tags)
                .eq(MessageConsumeExceptionRecordPO::getMsgKey, key)
                .set(MessageConsumeExceptionRecordPO::getDeleteTime, new Date())
                .set(MessageConsumeExceptionRecordPO::getDeleteFlag, Boolean.TRUE));

    }
}

